//
//  PiTuanViewController.m
//  中皮网
//
//  Created by ios程序员 on 15/10/29.
//  Copyright (c) 2015年 ios程序员. All rights reserved.
//

#import "PiTuanViewController.h"
#import "PiTuanView.h"
#import "PituanCell.h"
#import "PituandateViewController.h"
#import "PituanXiangqingViewController.h"
#import "PituanCollectionCell.h"
#import "BaseViewController.h"
#import "XianShangViewController.h"
#import "XianLiangViewController.h"
#import "PTdaTeViewController.h"
#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

#define w self.view.frame.size.width
#define h self.view.frame.size.height

#define Width self.frame.size.width
#define Height self.frame.size.height


@interface PiTuanViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic ,strong) UIView *baoMingView;
@property (nonatomic ,strong) UIView *weiView;
@property (nonatomic ,strong) UIView *rebeatView;
@property (nonatomic ,strong) UIView *baomingView;//报名
@property (nonatomic ,strong) UIImageView *baomingImage;

@property (nonatomic ,strong) UIView *zhekouView;//更多折扣

@property (nonatomic ,strong) UIView *youhuiView;//优惠

@property (nonatomic ,strong) UIView *baoming1View;
@property (nonatomic ,strong) UIImageView *baoming1Image;


@property (nonatomic ,strong) UICollectionView *toucollectionView;
@property (nonatomic ,strong) PiTuanView *barView;//自定义bar
@property (nonatomic ,strong) UIImageView *xianShangImage;//线上报名
@property (nonatomic ,strong) UIImageView *xiangliangImage;
@property (nonatomic ,strong) UITableView *tableView;
@property (nonatomic ,strong) UIImageView *image1;//代金卷
@property (nonatomic ,strong) UIImageView *image2;
@property (nonatomic ,strong) UIImageView *image3;
@property (nonatomic ,strong) UIButton *messageButton;//消息

@property (nonatomic ,strong) UIButton *rebeatButton;//折扣
@property (nonatomic ,strong) UIButton *tdrebeatButton;

@property (nonatomic ,strong) UIButton *rebeat1Button;
@property (nonatomic ,strong) UIButton *tdrebeat1Button;//今日折扣

@property (nonatomic ,strong) UIView *guangGaoView;
@property (nonatomic ,strong) UIImageView *guangGaoImage;

@property (nonatomic ,strong) UIView *zuijinTuanGouView;

@property (nonatomic ,strong) UIView *zuiJinView;

@property (nonatomic ,strong) UIImageView *zuiJImage1;
@property (nonatomic ,strong) UIImageView *zuiJImage2;
@property (nonatomic ,strong) UIImageView *zuiJImage3;
@property (nonatomic ,strong) UIImageView *zuiJImage4;
@property (nonatomic ,strong) UIImageView *zuiJImage5;
@property (nonatomic ,strong) UIImageView *zuiJImage6;
@property (nonatomic ,strong) UIImageView *zuiJImage7;
@property (nonatomic ,strong) UIImageView *zuiJImage8;
@property (nonatomic ,strong) UIImageView *zuiJImage9;
@property (nonatomic ,strong) UIImageView *zuiJImage10;


@property (nonatomic ,strong) UIView *caiNiLikeView;
@property (nonatomic ,strong) UILabel *caiNiLabel;
@property (nonatomic ,strong) UIImageView *caiNiImage;


@end

@implementation PiTuanViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
//    self.navigationController.navigationBarHidden = YES;
    
    [self barPituanView];
    [self tableViewSubView];
    [self.tableView registerClass:[PituanCell class] forCellReuseIdentifier:@"reuse"];
    
    self.messageButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.messageButton.frame = CGRectMake(320*WIDTH,0 , 50*WIDTH, 50*HEIGH);
    [self.messageButton setImage:[UIImage imageNamed:@"shop19.png"] forState:UIControlStateNormal];
    [self.navigationController.navigationBar addSubview:self.messageButton];
    [self.messageButton addTarget:self action:@selector(messageButton:) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)messageButton:(UIButton *)button
{
    
}
//自定义barView
- (void)barPituanView
{
    self.barView = [[PiTuanView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 70*HEIGH)];
    self.barView.backgroundColor = [UIColor redColor];
    [self.view addSubview:self.barView];

}
//tableview设置
- (void)tableViewSubView
{
    self.tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    self.tableView.rowHeight = 120;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 1) {
        return 2;
    }
    
    return 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    PituanCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
    cell.pitImage.backgroundColor = [UIColor blueColor];
    
    if (indexPath.row == 2) {
        
        cell.pitImage.backgroundColor = [UIColor blackColor];
        

    }
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 120;
    
}
/* cell头部标题高度 */
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 1450*HEIGH;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 100;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    self.baoMingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200*HEIGH)];
    self.xianShangImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ts"]];
    self.xianShangImage.frame = CGRectMake(0, 0, self.view.frame.size.width, 200*HEIGH) ;
    
    self.xiangliangImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"shop06"]];
    self.xiangliangImage.frame = CGRectMake(self.view.frame.size.width/2*HEIGH, 0, self.view.frame.size.width/2*WIDTH, 200*HEIGH) ;
//    [self.baoMingView addSubview:self.xiangliangImage];
    [self.baoMingView addSubview:self.xianShangImage];
    
    UITapGestureRecognizer *xiangshang = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(xianShangImages)];
    self.xianShangImage.userInteractionEnabled = YES;
    [self.xianShangImage addGestureRecognizer:xiangshang];
    
    UITapGestureRecognizer *xiangliang = [[UITapGestureRecognizer alloc ] initWithTarget:self action:@selector(xiangliangImages)];
    self.xiangliangImage.userInteractionEnabled = YES;
    [self.xiangliangImage addGestureRecognizer:xiangliang];
    
    
    [self.tableView addSubview:self.baoMingView];

    
    self.weiView = [[UIView alloc] initWithFrame:CGRectMake(10*WIDTH, 210*HEIGH, self.view.frame.size.width, 40*HEIGH)];
    self.image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yh1"]];
    self.image1.frame = CGRectMake(20*WIDTH, 0, 100*WIDTH, 40*HEIGH);
    self.image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yh2"]];
    self.image2.frame = CGRectMake(130*WIDTH, 0, 100*WIDTH, 40*HEIGH);
    self.image3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yh3"]];
    self.image3.frame = CGRectMake(240*WIDTH, 0, 100*WIDTH, 40*HEIGH);
    [self.weiView addSubview:self.image1];
    [self.weiView addSubview:self.image2];
    [self.weiView addSubview:self.image3];
    [self.tableView addSubview:self.weiView];
    
    self.youhuiView = [[UIView alloc] initWithFrame:CGRectMake(0, 260*HEIGH, w, 30*HEIGH)];
    UIButton *youhuiButton = [UIButton buttonWithType:UIButtonTypeCustom];
    youhuiButton.frame = CGRectMake(0, 0, w, 30*HEIGH);
    [youhuiButton setTitle:@"点击查看更多优惠劵" forState:UIControlStateNormal];
    youhuiButton.titleLabel.font = [UIFont systemFontOfSize:12];
    [youhuiButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [youhuiButton setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
    [self.youhuiView addSubview:youhuiButton];
    [self.tableView addSubview:self.youhuiView];

    
    self.rebeatButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.rebeatButton.backgroundColor = [UIColor yellowColor];
    self.rebeatButton.frame = CGRectMake(8*WIDTH, 530*HEIGH, 175*WIDTH, 110*HEIGH);
    [self.rebeatButton setImage:[UIImage imageNamed:@"jrzk"] forState:UIControlStateNormal];
    [self.tableView addSubview:self.rebeatButton];
    [self.rebeatButton addTarget:self action:@selector(rebeatButton:) forControlEvents:UIControlEventTouchUpInside];
    
    self.tdrebeatButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.tdrebeatButton.backgroundColor = [UIColor yellowColor];
    self.tdrebeatButton.frame = CGRectMake(185*WIDTH, 530*HEIGH, 175*WIDTH, 110*HEIGH);
    [self.tdrebeatButton setImage:[UIImage imageNamed:@"czzk"] forState:UIControlStateNormal];
    [self.tableView addSubview:self.tdrebeatButton];
    [self.tdrebeatButton addTarget:self action:@selector(tdrebeatButton:) forControlEvents:UIControlEventTouchUpInside];
    
    self.rebeat1Button = [UIButton buttonWithType:UIButtonTypeCustom];
    self.rebeat1Button.backgroundColor = [UIColor yellowColor];
    self.rebeat1Button.frame = CGRectMake(8*WIDTH, 642*HEIGH, 175*WIDTH, 110*HEIGH);
    [self.rebeat1Button setImage:[UIImage imageNamed:@"czzk"] forState:UIControlStateNormal];
    [self.tableView addSubview:self.rebeat1Button];
    [self.rebeat1Button addTarget:self action:@selector(rebeatButton:) forControlEvents:UIControlEventTouchUpInside];
    
    self.tdrebeat1Button = [UIButton buttonWithType:UIButtonTypeCustom];
    self.tdrebeat1Button.backgroundColor = [UIColor yellowColor];
    self.tdrebeat1Button.frame = CGRectMake(185*WIDTH, 642*HEIGH, 175*WIDTH, 110*HEIGH);
    [self.tdrebeat1Button setImage:[UIImage imageNamed:@"jrzk"] forState:UIControlStateNormal];
    [self.tableView addSubview:self.tdrebeat1Button];
    [self.tdrebeat1Button addTarget:self action:@selector(tdrebeatButton:) forControlEvents:UIControlEventTouchUpInside];
    
    self.zhekouView = [[UIView alloc] initWithFrame:CGRectMake(0, 760*HEIGH, w, 30*HEIGH)];
    UIButton *zhekouButton = [UIButton buttonWithType:UIButtonTypeCustom];
    zhekouButton.frame = CGRectMake(0, 0, w, 30*HEIGH);
    [zhekouButton setTitle:@"查看更多折扣劵" forState:UIControlStateNormal];
    zhekouButton.titleLabel.font = [UIFont systemFontOfSize:12];
    [zhekouButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [zhekouButton setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
    [self.zhekouView addSubview:zhekouButton];
    [self.tableView addSubview:self.zhekouView];



    
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(xiangqing)];
    self.image1.userInteractionEnabled = YES;
    [self.image1 addGestureRecognizer:tap1];
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(xiangqing)];
    self.image2.userInteractionEnabled = YES;
    [self.image2 addGestureRecognizer:tap2];
    UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(xiangqing)];
    self.image3.userInteractionEnabled = YES;
    [self.image3 addGestureRecognizer:tap3];
    
    
    
    
    self.baomingView = [[UIView alloc] initWithFrame:CGRectMake(0, 300*HEIGH, w, 100*HEIGH)];
    self.baomingImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"shop02"]];
    self.baomingImage.frame = CGRectMake(0, 0, w, 100*HEIGH);
    [self.baomingView addSubview:self.baomingImage];
    [self.tableView addSubview:self.baomingView];
    
    self.baoming1View = [[UIView alloc] initWithFrame:CGRectMake(0, 410*HEIGH, w, 100*HEIGH)];
    self.baoming1Image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"xlbm"]];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(baoming1ImageClick)];
    self.baoming1Image.userInteractionEnabled = YES;
    [self.baoming1Image addGestureRecognizer:tap];
    self.baoming1Image.frame = CGRectMake(0, 0, w, 100*HEIGH);
    [self.baoming1View addSubview:self.baoming1Image];
    [self.tableView addSubview:self.baoming1View];
    
    self.guangGaoView = [[UIView alloc] initWithFrame:CGRectMake(0, 800*HEIGH, w, 60*HEIGH)];
    self.guangGaoImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"hdby"]];
    self.guangGaoImage.frame = CGRectMake(0, 0, w, 60*HEIGH);
    [self.guangGaoView addSubview:self.guangGaoImage];
    [self.tableView addSubview:self.guangGaoView];
    
    self.zuijinTuanGouView = [[UIView alloc] initWithFrame:CGRectMake(0, 870*HEIGH, w, 30*HEIGH)];
    UIButton *zuijin = [UIButton buttonWithType:UIButtonTypeCustom];
    zuijin.frame = CGRectMake(0, 0, w, 30*HEIGH);
    [zuijin setTitle:@"最近团购" forState:UIControlStateNormal];
    zuijin.titleLabel.font = [UIFont systemFontOfSize:22];
    [zuijin setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [zuijin setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
    [self.zuijinTuanGouView addSubview:zuijin];
    [self.tableView addSubview:self.zuijinTuanGouView];
    
    self.zuiJinView = [[UIView alloc] initWithFrame:CGRectMake(0, 910*HEIGH, w, 400*HEIGH)];
    self.zuiJImage1 = [[UIImageView alloc] initWithFrame:CGRectMake(1*HEIGH, 0, w/2, 150*HEIGH)];
    self.zuiJImage2 = [[UIImageView alloc] initWithFrame:CGRectMake(w/2+2*HEIGH, 0, w/2-2*HEIGH, 150*HEIGH)];
    [self.zuiJImage1 setImage:[UIImage imageNamed:@"czqg"]];
    [self.zuiJImage2 setImage:[UIImage imageNamed:@"qlyx"]];
    [self.zuiJinView addSubview:self.zuiJImage1];
    [self.zuiJinView addSubview:self.zuiJImage2];
    
    self.zuiJImage3 = [[UIImageView alloc] initWithFrame:CGRectMake(2*HEIGH, 152*HEIGH, w/4-1*HEIGH, 110*HEIGH)];
    self.zuiJImage4 = [[UIImageView alloc] initWithFrame:CGRectMake(w/4+2*HEIGH, 152*HEIGH, w/4-1*HEIGH, 110*HEIGH)];
    self.zuiJImage5 = [[UIImageView alloc] initWithFrame:CGRectMake(w/4*2+2*HEIGH, 152*HEIGH, w/4-1*HEIGH, 110*HEIGH)];
    self.zuiJImage9 = [[UIImageView alloc] initWithFrame:CGRectMake(w/4*3+2*HEIGH, 152*HEIGH, w/4-1*HEIGH, 110*HEIGH)];
    self.zuiJImage6 = [[UIImageView alloc] initWithFrame:CGRectMake(2*HEIGH, 263*HEIGH, w/4-1*HEIGH, 110*HEIGH)];
    self.zuiJImage7 = [[UIImageView alloc] initWithFrame:CGRectMake(w/4+2*HEIGH, 263*HEIGH, w/4-1*HEIGH, 110*HEIGH)];
    self.zuiJImage8 = [[UIImageView alloc] initWithFrame:CGRectMake(w/4*2+2*HEIGH, 263*HEIGH, w/4-1*HEIGH, 110*HEIGH)];
    self.zuiJImage10 = [[UIImageView alloc] initWithFrame:CGRectMake(w/4*3+2*HEIGH, 263*HEIGH, w/4-1*HEIGH, 110*HEIGH)];

    
    [self.zuiJImage3 setImage:[UIImage imageNamed:@"1111"]];
    [self.zuiJImage4 setImage:[UIImage imageNamed:@"2222"]];
    [self.zuiJImage5 setImage:[UIImage imageNamed:@"3333"]];
    [self.zuiJImage6 setImage:[UIImage imageNamed:@"1111"]];
    [self.zuiJImage7 setImage:[UIImage imageNamed:@"2222"]];
    [self.zuiJImage8 setImage:[UIImage imageNamed:@"3333"]];
    [self.zuiJImage9 setImage:[UIImage imageNamed:@"1111"]];
    [self.zuiJImage10 setImage:[UIImage imageNamed:@"1111"]];


    
    
    [self.zuiJinView addSubview:self.zuiJImage3];
    [self.zuiJinView addSubview:self.zuiJImage4];
    [self.zuiJinView addSubview:self.zuiJImage5];
    [self.zuiJinView addSubview:self.zuiJImage6];
    [self.zuiJinView addSubview:self.zuiJImage7];
    [self.zuiJinView addSubview:self.zuiJImage8];
    [self.zuiJinView addSubview:self.zuiJImage9];
    [self.zuiJinView addSubview:self.zuiJImage10];

    self.caiNiLikeView = [[UIView alloc] initWithFrame:CGRectMake(0, 1310*HEIGH, w, 120)];
    self.caiNiImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, w, 80*HEIGH)];
    [self.caiNiImage setImage:[UIImage imageNamed:@"fsbs"]];
    self.caiNiLabel = [[UILabel alloc] initWithFrame:CGRectMake(155*HEIGH, 90*HEIGH, 80*HEIGH, 30*HEIGH)];
    self.caiNiLabel.text = @"猜你喜欢";
    self.caiNiLabel.font = [UIFont systemFontOfSize:20];
    [self.caiNiLikeView addSubview:self.caiNiLabel];
    [self.caiNiLikeView addSubview:self.caiNiImage];
    [self.tableView  addSubview:self.caiNiLikeView];
    


    
    [self.tableView addSubview:self.zuiJinView];
    
    return self.baoMingView;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    PTdaTeViewController *date = [[PTdaTeViewController alloc] init];
    [self.navigationController pushViewController:date animated:NO];
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}
- (void)messages
{
    
}

- (void)xiangqing
{
    PituanXiangqingViewController *xiangqi = [[PituanXiangqingViewController alloc] init];
    [self.navigationController pushViewController:xiangqi animated:NO];
}

- (void)rebeatButton:(UIButton *)button
{
    
    
}

- (void)tdrebeatButton:(UIButton *)button
{
    
}

//向上报名跳转
- (void)xianShangImages
{
    XianShangViewController *view = [[XianShangViewController alloc] init];
    [self.navigationController pushViewController:view animated:NO];
}

- (void)xiangliangImages
{
    
}
//限量报名跳转
- (void)baoming1ImageClick
{
    XianLiangViewController *xlView = [[XianLiangViewController alloc] init];
    [self.navigationController pushViewController:xlView animated:NO];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
